package com.sjyl.kaoshitong.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.orhanobut.logger.Logger;
import com.sjyl.kaoshitong.R;
import com.sjyl.kaoshitong.beans.QuestionItem;

import java.util.List;

/**
 * Created by ChangerLow on 15/6/24.
 * Email: changerlow@qq.com
 */
public class QARecyclerViewAdapter extends RecyclerView.Adapter<QARecyclerViewAdapter.ViewHolder> {
    private static final String TAG = "QARecyclerViewAdapter";
    private List<QuestionItem> dataSet = null;
    private ViewHolder.MyOnItemClickListener mItemClickListener;
    // private QARecyclerViewAdapter.MyOnItemClickListener mItemClickListener;

    public QARecyclerViewAdapter(List<QuestionItem> list) {
        this.dataSet = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_qa_reward_layout, parent, false);
        ViewHolder vh = new ViewHolder(v, mItemClickListener);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return 20;
    }

    public void setOnItemClickListener(ViewHolder.MyOnItemClickListener listener){
        this.mItemClickListener = listener;
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {

        public ViewHolder(View itemView, final MyOnItemClickListener listener) {
            super(itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(listener != null)
                        listener.OnItemClick(v, getAdapterPosition());
                    //AlertDialog dialog =new AlertDialog.Builder(itemView.getContext()).setTitle("This is a Dialog").setMessage("You click "+ getAdapterPosition()+" element!").show();
                    Logger.d(TAG, "Element " + getAdapterPosition() + " clicked.");
                }
            });

        }

        public interface MyOnItemClickListener{
            void OnItemClick(View view, int position);
        }
    }
}
